package com.guozcc.bootweb.platform.config.mybatis;

import com.guozcc.bootweb.platform.config.mybatis.intercept.AutoExecutorInterceptor;
import com.guozcc.bootweb.platform.config.mybatis.intercept.AutoParameterHandlerInterceptor;
import com.guozcc.bootweb.platform.config.mybatis.intercept.AutoResultSetHandlerInterceptor;
import com.guozcc.bootweb.platform.config.mybatis.intercept.AutoStatementHandlerInterceptor;
import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.stereotype.Component;


/**
 * guozcc by 20230914
 *  mybatis的四种拦截器插件
 *      1、Executor执行方法，创建一个StatementHandler对象
 *      2、StatementHandler 调用ParameterHandler对象的setParameters()方法
 *      3、StatementHandler 调用 Statement对象的execute()方法
 *      4、StatementHandler 调用ResultSetHandler对象的handleResultSets()方法，返回最终结果
 */

@Component
public class AutoConfigurationCustomizer implements ConfigurationCustomizer {
    @Override
    public void customize(Configuration configuration) {
        //设置自定义Executor拦截器
        configuration.addInterceptor(new AutoExecutorInterceptor());
        //设置自定义StatementHandler拦截器
        configuration.addInterceptor(new AutoStatementHandlerInterceptor());
        //设置自定义ResultSetHandler拦截器
        configuration.addInterceptor(new AutoResultSetHandlerInterceptor());
        //设置自定义ParameterHandler拦截器
        configuration.addInterceptor(new AutoParameterHandlerInterceptor());

        //设置ObjectWrapperFactory  （结果集字段小写）
        configuration.setObjectWrapperFactory(new ResultToLowerCaseFactory());
    }
}

